home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_amanda.idb / usr / freeware / bin / amstatus.z / amstatus
Encoding:
Text File  |  1999-07-16  |  12.2 KB  |  452 lines

  1. #!/usr/bin/perl5
  2. #
  3.  
  4. # Run perl.
  5. eval '(exit $?0)' && eval 'exec /usr/bin/perl5 -S $0 ${1+"$@"}'
  6.      & eval 'exec /usr/bin/perl5 -S $0 $argv:q'
  7.         if 0;
  8.  
  9. require "newgetopt.pl";
  10.  
  11. $confdir="/usr/freeware/etc/amanda";
  12. $prefix='/usr/freeware';
  13.  
  14. $exec_prefix="${prefix}";
  15. $libexecdir="/usr/freeware/libexec";
  16.  
  17. $USE_VERSION_SUFFIXES='no';
  18. $suf = '';
  19. if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
  20.         $suf='-2.4.1p1';
  21. }
  22.  
  23. $result = &NGetOpt (    "summary","dumping|d",
  24.                             "waitdumping|wdumping","waittaper|wtaper",
  25.                             "dumpingtape|dtape", "writingtape|wtape",
  26.                             "finished","failed|error",
  27.                             "estimate","gestimate|gettingestimate",
  28.                             "config|c:s","file:s",
  29.                             );
  30. if($result !=1 ) {
  31.     usage();
  32. }
  33.  
  34. if( defined $opt_config ) {
  35.     $conf = $opt_config;
  36. }
  37. else {
  38.     if($#ARGV == 0 ) {
  39.         $conf=$ARGV[0];
  40.     }
  41.     else {
  42.         usage();
  43.     }
  44. }
  45.  
  46. if ( ! -d "$confdir/$conf" ) {
  47.     die "amdump$suf: could not find directory $confdir/$conf";
  48. }
  49.  
  50. $pwd = `pwd`;
  51. chomp $pwd;
  52. chdir "$confdir/$conf";
  53.  
  54. $logdir=`$libexecdir/getconf$suf logdir`;
  55. chomp $logdir;
  56. $errfile="$logdir/amdump";
  57.  
  58. $nb_options = defined( $opt_summary ) +
  59.                   defined( $opt_dumping ) +
  60.                   defined( $opt_waitdumping ) +
  61.                   defined( $opt_waittaper ) +
  62.                   defined( $opt_dumpingtape ) +
  63.                   defined( $opt_writingtape ) +
  64.                   defined( $opt_finished ) +
  65.                   defined( $opt_estimate ) +
  66.                   defined( $opt_gestimate ) +
  67.                   defined( $opt_failed );
  68.  
  69. if($nb_options == 0 ) {
  70.     $opt_summary      = 1;
  71.     $opt_dumping     = 1;
  72.     $opt_waitdumping = 1;
  73.     $opt_waittaper   = 1;
  74.     $opt_dumpingtape = 1;
  75.     $opt_writingtape = 1;
  76.     $opt_finished    = 1;
  77.     $opt_failed      = 1;
  78.     $opt_gestimate   = 1;
  79.     $opt_estimate    = 1;
  80. }
  81.  
  82. if( defined $opt_file) {
  83.     $errfile = "$pwd/$opt_file";
  84.     $errfile = "$logdir/$opt_file" if ( ! (-f $errfile ));
  85. }
  86.  
  87. open(AMDUMP,"<$errfile") || die("no $errfile file");
  88. print "Using $errfile\n\n";
  89.  
  90. while(<AMDUMP>) {
  91.     if(/^setup_estimate: (\S+):(\S+): command .*, options:.*$/) {
  92.         $host=$1;
  93.         $partition=$2;
  94.         if($hosts{$host} != 1 ) {
  95.             push @hosts, $host;
  96.             $hosts{$host}=1;
  97.         }
  98.         $$host=1;
  99.         push @$host, $partition;
  100.     }
  101.     elsif(/^got result for host (\S+) disk (\S+): (\d+) -> (\d+)K, .*$/) {
  102.         $host=$1;
  103.         $partition=$2;
  104.         $hostpart="$host$partition";
  105.         $estimate{$hostpart}=1;
  106.         $level{$hostpart}=$3;
  107.         $esize{$hostpart}=$4;
  108.     }
  109.     elsif(/^getting estimates took .*$/) {
  110.         $estimate_done=1;
  111.     }
  112.     elsif(/^GENERATING SCHEDULE:$/) {
  113.         $generating_schedule=1;
  114.     }
  115.     elsif(/^(\S+) (\S+) (\d+) (\d+) \d+:\d+:\d+:\d+:\d+:\d+ (\d+) \d+$/) {
  116.         if($generating_schedule == 1 ) {
  117.             $host=$1;
  118.             $partition=$2;
  119.             $hostpart="$host$partition";
  120.             $level{"$hostpart"}=$4;
  121.             $size=$5;
  122.             $size=32 if $size<32;
  123.             $esize{$hostpart}=$size;
  124.             $size{$hostpart}=$size;
  125.             $degr_level{$hostpart}=-1;
  126.         }
  127.     }
  128.     elsif(/^(\S+) (\S+) (\d+) (\d+) \d+:\d+:\d+:\d+:\d+:\d+ (\d+) \d+ (\d+) \d+:\d+:\d+:\d+:\d+:\d+ ([-]*\d+) \d+$/) {
  129.         if($generating_schedule == 1 ) {
  130.             $host=$1;
  131.             $partition=$2;
  132.             $hostpart="$host$partition";
  133.             $level{$hostpart}=$4;
  134.             $size=$5;
  135.             $size=32 if $size<32;
  136.             $esize{$hostpart}=$size;
  137.             $size{$hostpart}=$size;
  138.             $degr_level{$hostpart}=$6;
  139.             $degr_size{$hostpart}=$7;
  140.             $degr_size{$hostpart}=32 if ($7 < 32);
  141.         }
  142.     }
  143.     elsif(/^driver: send-cmd time \S+ to dumper\d*: (FILE-DUMP|PORT-DUMP) (\d+-\d+) (\S+) (\S+) (\S+) (\d+) .*$/) {
  144.         $host=$4;
  145.         $partition=$5;
  146.         $hostpart="$host$partition";
  147.         $serial=$2;
  148.         $dump_started{$hostpart}=1;
  149.         $dump_finished{$hostpart}=0;
  150.         $holding_file{$hostpart}=$3;
  151.         if(     $level{$hostpart} != $6 &&
  152.            $degr_level{$hostpart} == $6) {
  153.             $level{$hostpart}=$degr_level{$hostpart};
  154.             $size{$hostpart} =$degr_size{$hostpart};
  155.             $esize{$hostpart}=$degr_size{$hostpart};
  156.         }
  157.         $serial{"$serial"}=$hostpart;
  158.     }
  159.     elsif(/^driver: result time \S+ from dumper\d+: FAILED (\d+-\d+) (.*)$/) {
  160.         $serial=$1;
  161.         $error=$2;
  162.         $hostpart=$serial{$serial};
  163.         $dump_finished{$hostpart}=-1;
  164.         $error{$hostpart}=$error;
  165.     }
  166.     elsif(/^driver: result time \S+ from dumper\d+: TRY-AGAIN (\d+-\d+) (.*)$/) {
  167.         $serial=$1;
  168.         $error=$2;
  169.         $hostpart=$serial{$serial};
  170.         $dump_finished{$hostpart}=-1;
  171.         $error{$hostpart}=$error;
  172.     }
  173.     elsif(/^driver: result time \S+ from dumper\d+: DONE (\d+-\d+) (\d+) (\d+) (\d+) \[.*\]$/) {
  174.         $serial=$1;
  175.         $origsize=$2;
  176.         $outputsize=$3;
  177.         $hostpart=$serial{$serial};
  178.         $size{$hostpart}=$outputsize;
  179.         $dump_finished{$hostpart}=1;
  180.     }
  181.     elsif(/^driver: finished-cmd time \S+ dumper\d+ dumped (\S+):(\S+)$/){
  182.     }
  183.     elsif(/^driver: send-cmd time \S+ to taper: FILE-WRITE (\d+-\d+) (\S+) (\S+) (\S+) \d*.*$/){
  184.         $serial=$1;
  185.         $host=$3;
  186.         $partition=$4;
  187.         $hostpart="$host$partition";
  188.         $serial{$serial}=$hostpart;
  189.         $taper_started{$hostpart}=1;
  190.     }
  191.     elsif(/^driver: send-cmd time \S+ to taper: PORT-WRITE (\d+-\d+) (\S+) (\S+) \d*( \d*|)$/){
  192.         $serial=$1;
  193.         $host=$2;
  194.         $partition=$3;
  195.         $hostpart="$host$partition";
  196.         $serial{$serial}=$hostpart;
  197.         $taper_started{$hostpart}=1;
  198.     }
  199.     elsif(/^driver: result time \S+ from taper: DONE (\d+-\d+) (\S+) .*$/) {
  200.         $serial=$1;
  201.         $label=$2;
  202.         $hostpart=$serial{$serial};
  203.         $taper_finished{$hostpart}=1;
  204.     }
  205.     elsif(/^driver: result time \S+ from taper: TAPE-ERROR (\d+-\d+) (.+)$/) {
  206.         $serial=$1;
  207.         $error=$2;
  208.         $hostpart=$serial{$serial};
  209.         $taper_finished{$hostpart}=-1;
  210.         $error{$hostpart}=$error;
  211.     }
  212.     elsif(/^planner: FAILED (\S+) (\S+) (\d+) (.*)$/) {
  213.         $host=$1;
  214.         $partition=$2;
  215.         $hostpart="$host$partition";
  216.         $dump_started{$hostpart}=-1;
  217.         $level{$hostpart}=$3;
  218.         $error{$hostpart}=$4;
  219.     }
  220.     elsif(/^dump of driver schedule after start degraded mode:$/) {
  221.         $start_degraded_mode=1;
  222.     }
  223.     elsif(/^driver: state time \S+ free kps: (\d+) space: (\d+) taper: (\S+) idle-dumpers: (\d+) qlen tapeq: (\d+) runq: (\d+) stoppedq: (\d+) wakeup: (\d+) driver-idle: (\S+)$/) {
  224.         $free_kps=$1;
  225.         $free_space=$2;
  226.         $status_taper=$3;
  227.         $idle_dumpers=$4;
  228.         $qlen_tapeq=$5;
  229.         $runq=$6;
  230.         $stoppedq=$7;
  231.         $wakeup=$8;
  232.         $status_driver=$9;
  233.     }
  234. }
  235.  
  236. close(AMDUMP);
  237.  
  238. foreach $host (@hosts) {
  239.     foreach $partition (@$host) {
  240.         $nb_partition++;
  241.         $hostpart = "$host$partition";
  242.         if($estimate_done != 1) {
  243.             if($estimate{$hostpart} != 1) {
  244.                 if( defined $opt_gestimate ) {
  245.                     printf "%-40s", "$host:$partition";
  246.                     print "            getting estimate\n";
  247.                 }
  248.             }
  249.             else {
  250.                 if( defined $opt_estimate ) {
  251.                     printf "%-40s", "$host:$partition";
  252.                     printf "%2d",  $level{$hostpart};
  253.                     printf "%8dk", $esize{$hostpart};
  254.                     print " estimate done\n";
  255.                 }
  256.                 $epartition++;
  257.                 $estsize += $esize{$hostpart};
  258.             }
  259.         }
  260.         else {
  261.             $epartition++;
  262.             $estsize += $esize{$hostpart};
  263.             if($estimate{$hostpart} != 1) {
  264.                 if( defined $opt_failed ) {
  265.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  266.                     print " no estimate\n";
  267.                 }
  268.                 $epartition--;
  269.                 $estsize -= $esize{$hostpart};
  270.                 $fpartition++;
  271.             }
  272.             elsif($dump_started{$hostpart} == -1) {
  273.                 if( defined $opt_failed ) {
  274.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  275.                     printf " " . $error{$hostpart} . "\n";
  276.                 }
  277.                 $fpartition++;
  278.                 $fsize+=$esize{$hostpart};
  279.             }
  280.             elsif($dump_started{$hostpart} != 1) {
  281.                 if( defined $opt_waitdumping ) {
  282.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  283.                     printf "%8dk", $esize{$hostpart};
  284.                     print " wait for dumping\n";
  285.                 }
  286.                 $wpartition++;
  287.                 $wsize += $esize{$hostpart};
  288.             }
  289.             elsif($dump_started{$hostpart} == 1 &&
  290.                     $dump_finished{$hostpart} == -1) {
  291.                 if( defined $opt_failed ) {
  292.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  293.                     printf " " . $error{$hostpart} . "\n";
  294.                 }
  295.                 $fpartition++;
  296.                 $fsize+=$esize{$hostpart};
  297.             }
  298.             elsif($dump_started{$hostpart} == 1 &&
  299.                     $dump_finished{$hostpart} != 1 &&
  300.                     $taper_started{$hostpart} == 1) {
  301.                 if( defined $opt_dumpingtape ) {
  302.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  303.                     printf "%8dk", $size{$hostpart};
  304.                     print " dumping to tape\n";
  305.                 }
  306.                 $dtpartition++;
  307.                 $dtesize += $esize{$hostpart};
  308.             }
  309.             elsif($dump_started{$hostpart} == 1 &&
  310.                     $dump_finished{$hostpart} != 1) {
  311.                 if( defined $opt_dumping ) {
  312.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  313.                     printf "%8dk", $esize{$hostpart};
  314.                     print " dumping";
  315.                 }
  316.                 $size = dump_size($holding_file{$hostpart});
  317.                 if( defined $opt_dumping ) {
  318.                     printf "%8dk", $size/1024;
  319.                     if($size{$hostpart} != 0) {
  320.                         printf " (%6.2f\%)", 
  321.                                  (100.0*$size)/(1024.0*$esize{$hostpart});
  322.                     }
  323.                     print "\n";
  324.                 }
  325.                 $dupartition++;
  326.                 $dusize += $size/1024;
  327.                 $duesize += $esize{$hostpart};
  328.             }
  329.             elsif($dump_finished{$hostpart} == 1 &&
  330.                     $taper_started{$hostpart} != 1) {
  331.                 if( defined $opt_waittaper ) {
  332.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  333.                     printf "%8dk", $size{$hostpart};
  334.                     print " dump done, wait for writing to tape\n";
  335.                 }
  336.                 $dpartition++;
  337.                 $dsize += $size{$hostpart};
  338.                 $desize += $esize{$hostpart};
  339.                 $twpartition++;
  340.                 $twsize += $size{$hostpart};
  341.                 $twesize += $esize{$hostpart};
  342.             }
  343.             elsif($taper_started{$hostpart} == 1 &&
  344.                     $taper_finished{$hostpart} == 0) {
  345.                 if( defined $opt_writingtape ) {
  346.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  347.                     printf "%8dk", $size{$hostpart};
  348.                     print " writing to tape\n";
  349.                 }
  350.                 $dpartition++;
  351.                 $dsize += $size{$hostpart};
  352.                 $desize += $esize{$hostpart};
  353.                 $tapartition++;
  354.                 $tasize += $size{$hostpart};
  355.                 $taesize += $esize{$hostpart};
  356.             }
  357.             elsif($taper_started{$hostpart} == 1 &&
  358.                     $taper_finished{$hostpart} == -1) {
  359.                 if( defined $opt_failed ) {
  360.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  361.                     printf "%8dk", $size{$hostpart};
  362.                     print " failed to taped\n";
  363.                 }
  364.                 $dpartition++;
  365.                 $dsize += $size{$hostpart};
  366.                 $desize += $esize{$hostpart};
  367.                 $tfpartition++;
  368.                 $tfsize += $size{$hostpart};
  369.                 $tfesize += $esize{$hostpart};
  370.             }
  371.             elsif($taper_finished{$hostpart} == 1) {
  372.                 if( defined $opt_finished ) {
  373.                     printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  374.                     printf "%8dk", $size{$hostpart};
  375.                     print " finished\n";
  376.                 }
  377.                 $dpartition++;
  378.                 $dsize += $size{$hostpart};
  379.                 $desize += $esize{$hostpart};
  380.                 $tpartition++;
  381.                 $tsize += $size{$hostpart};
  382.                 $tesize += $esize{$hostpart};
  383.             }
  384.             else {
  385.                 printf "%-40s%2d", "$host:$partition", $level{$hostpart};
  386.                 print " unknown state\n";
  387.             }
  388.         }
  389.     }
  390. }
  391.  
  392. if ($opt_summary == 1) {
  393.     print "\n";
  394.     print  "SUMMARY          part     real estimated\n";
  395.     print  "                          size      size\n";
  396.     printf "partition       : %3d\n", $nb_partition;
  397.     printf "estimated       : %3d %18dk\n", $epartition , $estsize;
  398.     printf "failed          : %3d %18dk\n", $fpartition , $fsize;
  399.     printf "wait for dumping: %3d %18dk\n", $wpartition , $wsize;
  400.     printf "dumping to tape : %3d %18dk\n", $dtpartition, $dtesize;
  401.     printf "dumping         : %3d %8dk %8dk\n", $dupartition, $dusize, $duesize;
  402.     printf "dumped          : %3d %8dk %8dk\n", $dpartition , $dsize , $desize;
  403.     printf "wait for writing: %3d %8dk %8dk\n", $twpartition, $twsize, $twesize;
  404.     printf "writing to tape : %3d %8dk %8dk\n", $tapartition, $tasize, $taesize;
  405.     printf "failed to tape  : %3d %8dk %8dk\n", $tfpartition, $tfsize, $tfesize;
  406.     printf "taped           : %3d %8dk %8dk\n", $tpartition , $tsize , $tesize;
  407.     if($idle_dumpers ==0) {
  408.         printf "all dumpers active\n";
  409.     }
  410.     else {
  411.         printf "%d dumpers idle  : %s\n", $idle_dumpers, $status_driver;
  412.     }
  413.     if($status_taper eq "writing") {
  414.         printf "taper writing, tapeq: %d\n", qlen_tapeq;
  415.     }
  416.     else {
  417.         printf "taper idle\n";
  418.     }
  419.     printf "network free kps: %d\n", $free_kps;
  420.     printf "holding space   : %d\n", $free_space;
  421. }
  422.  
  423. sub dump_size() {
  424.     local($filename) = @_;
  425.     local($size);
  426.    local($dsize)=0;
  427.     local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  428.            $atime,$mtime,$ctime,$blksize,$blocks);
  429.     while ($filename ne "") {
  430.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  431.                 $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);
  432.         $size=$size-32768 if $size > 32768;
  433.         $dsize += $size;
  434.         open(DUMP,$filename);
  435.         $filename = "";
  436.         while(<DUMP>) {
  437.             if(/^CONT_FILENAME=(.*)$/) { $filename = $1; last }
  438.             last if /^To restore, position tape at start of file and run/;
  439.         }
  440.         close(DUMP);
  441.    }
  442.     return $dsize;
  443. }
  444.  
  445. sub usage() {
  446.     print "amstatus [--config] config [--file amdump_file]\n";
  447.     print "         [--summary] [--dumping] [--waitdumping] [--waittaper]\n";
  448.     print "         [--dumpingtape] [--writingtape] [--finished] [--failed]\n";
  449.     print "         [--estimate] [--gestimate]\n";
  450.     exit 0;
  451. }
  452.